home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / UI / UI_CLOCK.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  3KB  |  136 lines

  1. /****************************************************************
  2.  
  3.     ui_clock.c      Clock routines for
  4.             The Bywater Graphical User Interface
  5.  
  6.             Copyright (c) 1991, Ted A. Campbell
  7.  
  8.             Bywater Software
  9.             P. O. Box 4023 
  10.             Duke Station 
  11.             Durham, NC  27706
  12.  
  13.             email: tcamp@hercules.acpub.duke.edu
  14.  
  15.     Copyright and Permissions Information:
  16.  
  17.     All U.S. and international copyrights are claimed by the
  18.     author. The author grants permission to use this code
  19.     and software based on it under the following conditions:
  20.     (a) in general, the code and software based upon it may be 
  21.     used by individuals and by non-profit organizations; (b) it
  22.     may also be utilized by governmental agencies in any country,
  23.     with the exception of military agencies; (c) the code and/or
  24.     software based upon it may not be sold for a profit without
  25.     an explicit and specific permission from the author, except
  26.     that a minimal fee may be charged for media on which it is
  27.     copied, and for copying and handling; (d) the code must be 
  28.     distributed in the form in which it has been released by the
  29.     author; and (e) the code and software based upon it may not 
  30.     be used for illegal activities. 
  31.  
  32. ****************************************************************/
  33.  
  34. #include "stdio.h"
  35. #include "time.h"
  36. #include "gr.h"
  37. #include "ui.h"
  38.  
  39. #ifdef  __STDC__
  40. #include "stdlib.h"
  41. #else
  42. #define time_t  long
  43. extern char *getenv();
  44. #endif
  45.  
  46. /* #define      USESMALLFONT    */
  47.  
  48. int cl_initialized = FALSE;
  49. static int cl_x, cl_y, cl_fore, cl_back;
  50. static char clock_buf[ 36 ];
  51. static char env_buf[ 48 ];
  52. static int last_time;
  53.  
  54. ui_clinit( x, y, fore, back )
  55.     int x, y, fore, back;
  56.     {
  57.     static time_t now;
  58.     struct tm *clock_time;
  59.     register int c;
  60.  
  61.     time( &now );
  62.     clock_time = localtime( &now );
  63.  
  64.     if ( getenv( "TZ" ) == NULL )
  65.         {
  66.         strcpy( env_buf, "LOC" );
  67.         }
  68.     else
  69.         {
  70.         strcpy( env_buf, getenv( "TZ" ) );
  71.         }
  72.  
  73.     if ( clock_time->tm_isdst == 0 )
  74.         {
  75.         env_buf[ 3 ] = 0;
  76.         }
  77.     else
  78.         {
  79.         for ( c = 0; c < 4; ++c )
  80.             {
  81.             env_buf[ c ] = env_buf[ c + 4 ];
  82.             }
  83.         }
  84.  
  85.     cl_x = x;
  86.     cl_y = y;
  87.     cl_fore = fore;
  88.     cl_back = back;
  89.     cl_initialized = TRUE;
  90.     }
  91.  
  92. ui_clock()
  93.     {
  94.     static time_t now;
  95. #ifdef  USESMALLFONT
  96.     int save_fysize, save_font;
  97. #endif
  98.     struct tm *clock_time;
  99.  
  100.     if ( cl_initialized == FALSE )
  101.         {
  102.         return FALSE;
  103.         }
  104.  
  105.     time( &now );
  106.     clock_time = localtime( &now );
  107.  
  108.     if ( clock_time->tm_min == last_time )
  109.         {
  110.         return TRUE;
  111.         }
  112.  
  113. #ifdef  USESMALLFONT
  114.     save_fysize = ui_grwind->fysize;
  115.     save_font   = ui_grwind->font;
  116.     gr_font( ui_screen, save_font, save_fysize * 4 );
  117. #endif
  118.  
  119.     last_time = clock_time->tm_min;
  120.     sprintf( clock_buf, "%02d:%02d %s",
  121.         clock_time->tm_hour, clock_time->tm_min, env_buf );
  122.     gr_text( ui_screen, cl_x,
  123.         cl_y, clock_buf, cl_fore, cl_back );
  124.  
  125. #ifdef  USESMALLFONT
  126.     gr_font( ui_screen, save_font, save_fysize );
  127. #endif
  128.  
  129.     }
  130.  
  131. ui_clforce()
  132.     {
  133.     last_time = 63;
  134.     ui_clock();
  135.     }
  136.